import { Action, createReducer, on } from '@ngrx/store';
import {
  addPersonListItem,
  deletePersonListItem,
  changeStatus,
} from '../actions/person.actions';

export const personFeatureKey = 'person';
export interface PersonListItem {
  id: string;
  name: string;
  isChecked: boolean;
}
export type State = Array<PersonListItem>;

export const initialState: State = [
  {
    id: '1',
    name: '张三',
    isChecked: true,
  },
];
interface MyAction extends Action {
  payload?: any;
}
export const reducer = createReducer(
  initialState,
  on(addPersonListItem, (state, action: MyAction) => {
    return [...state.concat([action.payload])];
  }),
  on(deletePersonListItem, (state, action: MyAction) => {
    return action.payload;
  }),
  on(changeStatus, (state, action: MyAction) => {
    return action.payload;
  })
);
